package com.example.asus.a1210;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    RecyclerView rv;
    List<String> data=new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        rv=(RecyclerView)findViewById(R.id.rv);
        rv.setLayoutManager(new LinearLayoutManager(this));
        rv.setAdapter(new MyAdapter());
        data.add("马飞");
        data.add("杨卓");
        data.add("钻石五");

    }
    class MyAdapter extends RecyclerView.Adapter<MyViewHolder>{

        @Override
        public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return new MyViewHolder(LayoutInflater.from(MainActivity.this).inflate(R.layout.cell,parent,false));

        }
        @Override
        public void onBindViewHolder(MyViewHolder holder, final int position) {
            holder.nick.setText(data.get(position));
            holder.record.setText("聊天记录待定....");
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    data.remove(position);
                    notifyItemRemoved(position);
                }
            });
        }
        @Override
        public int getItemCount() {
            return data.size();
        }
    }

    class MyViewHolder extends  RecyclerView.ViewHolder{
        TextView nick;
        TextView record;
        public MyViewHolder(View itemView){
            super(itemView);
            nick=(TextView)itemView.findViewById(R.id.nick);
            record=itemView.findViewById(R.id.recode);
        }
    }
}
